from CommonLib import *

ai_ele_global_config_default = {
    'with-hardwork': True
}
ai_ele_global_config = {
    'with-hardwork': True,
    'useAuth': False,
    'useHttps': False
}


class GlobalStatus:

    def __init__(self):
        self.send_cond = threading.Condition()
        self.__class_lock = threading.RLock()
        self.__normal_map = dict()
        self.config = ai_ele_global_config

    def Ins2NormalMap(self, s_id, h_thread):
        if type(s_id) is not str:
            return False
        self.__class_lock.acquire()
        if s_id in self.__normal_map:
            self.__normal_map[s_id].append(h_thread)
        else:
            h_list = [h_thread]
            self.__normal_map[s_id] = h_list
        self.__class_lock.release()
        return True

    def Get4NormalMap(self, s_id):
        if type(s_id) is not str:
            return None
        ret = []
        self.__class_lock.acquire()
        if s_id in self.__normal_map:
            ret = self.__normal_map[s_id]
        self.__class_lock.release()
        return ret

    def Del4NormalMap(self, s_id):
        if type(s_id) is not str:
            return False
        self.__class_lock.acquire()
        if s_id in self.__normal_map:
            self.__normal_map.pop(s_id)
        self.__class_lock.release()
        return True

    def WaitSend(self):
        self.send_cond.acquire()
        self.send_cond.wait()
        self.send_cond.release()

    def NotifySend(self):
        self.send_cond.acquire()
        self.send_cond.notifyAll()
        self.send_cond.release()


ai_ele_global_status = GlobalStatus()
